/**
 * Created by 追风少年 on 2018/6/7.
 */
var tableObj;
var table;

var closeWinAndFlush = function(){
    layer.closeAll('iframe'); //关闭所有的iframe层
    doQuery(1);
};

layui.use('table', function () {
    table = layui.table;
    tableObj = table.render({
        elem: '#datas',
        url: '/admin/sysUser/findPage',
        height: 'full-220', //设置高度
        width: $("body").width() - 35,
        id: "datas",
        method: 'post',
        cols: [[ //标题栏
            {checkbox: true},
            {field: 'fullname', title: '用户名', width: 220, sort: false},
            // {field: 'loginaccount', title: '登录账号', width: 220, sort: false},
            {field: 'cellphone', title: '手机号', width: 220, sort: false},
            {field: 'createtime', title: '创建时间', width: 220, sort: false}
        ]],
        page: true,
        limits: [10, 20, 30, 50, 100],
        limit: 10
        //支持所有基础参数
    });
    $("#doQuery").click(function () {
        doQuery(1);
    });

    $("#add").click(function () {
        Utils.openInputWin("新增用户",'/admin/sysUser/inputPage');
    });

    $("#edit").click(function () {
        var checkStatus = table.checkStatus('datas'); //test即为基础参数id对应的值
        var rows = checkStatus.data;
        if(rows.length != 1){
            layer.msg(COMMON.MSG.EDIT_MSG);
            return false;
        }
        Utils.openInputWin("修改用户",'/admin/sysUser/inputPage?id='+rows[0].userid);
    });

    $("#info").click(function () {
        var checkStatus = table.checkStatus('datas'); //test即为基础参数id对应的值
        var rows = checkStatus.data;
        if(rows.length != 1){
            layer.msg(COMMON.MSG.INFO_MSG);
            return false;
        }
        Utils.openInfoWin("用户详情",'/admin/sysUser/infoPage?id='+rows[0].roleid);
    });

});
function doQuery(pagenum) {
    tableObj.reload({ //其它参数在此省略
        id: 'datas',
        method: 'post',
        pagenum: pagenum,
        url: '/admin/sysUser/findPage?' + decodeURIComponent(decodeURI($('#form').serialize()), true)
    });
}